package com.aegean.MonitorExamSYS.center.action;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.center.business.CenterBusiness;
import com.aegean.MonitorExaxSYS.model.ExamPosition;
import com.opensymphony.xwork2.ActionSupport;

@Controller("showPositionListForCenter")
@Scope("prototype")
public class showPositionListForCenter extends ActionSupport implements
		ServletRequestAware {
	/**
	 * 
	 */
	@Resource
	CenterBusiness business;
	private static final long serialVersionUID = 8197452721045695073L;
	private List<ExamPosition> positions;
	private int total;
	private int unit_Id;
	private Date startTime;
	private Date endTime;
	private HttpSession session;
	private HttpServletRequest request;
	private Map<Integer, List<Integer>> con_PositionsMap;
	public List<ExamPosition> getPositions() {
		return positions;
	}

	public void setPositions(List<ExamPosition> positions) {
		this.positions = positions;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public int getUnit_Id() {
		return unit_Id;
	}

	public void setUnit_Id(int unit_Id) {
		this.unit_Id = unit_Id;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		con_PositionsMap = (Map<Integer, List<Integer>>) session
				.getAttribute("confirmConductionsMap");
		if (!con_PositionsMap.containsKey(unit_Id)) {
			positions = null;
			total = 0;
		} else {
			positions = business.showPositionList(unit_Id, startTime, endTime);
			total = positions.size();
		}
		return SUCCESS;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request = arg0;
		this.session = request.getSession();

	}

}
